package com.yaoyong.yy_demo.module.springboot.thymeleaf;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 86188
 */
@Controller
@SpringBootApplication
public class ThymeleafApplication {

    public static void main(String[] args) {
        SpringApplication.run(ThymeleafApplication.class, args);
    }

    @RequestMapping("/thymeleaf")
    public String thymeleaf(Model model) {
        Person singlePeople = new Person("张三", 23);
        List<Person> people = new ArrayList<>();
        Person p1 = new Person("李四", 24);
        Person p2 = new Person("王五", 25);
        Person p3 = new Person("赵六", 26);
        Person p4 = new Person("wisely", 26);
        people.add(p1);
        people.add(p2);
        people.add(p3);
        people.add(p4);
        model.addAttribute("singlePeople", singlePeople);
        model.addAttribute("people", people);
        return "thymeleaf";
    }

}

class Person {
    private String name;
    private int age;

    public Person() {
    }

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
}
